const query = require('./sqlite')
const config =  require('../config/sqlite')
const tables = require('../config/tables')
//const sqlite = require('./sqlite')
class recordSql {
  findAllData() {
    let  _sql = `SELECT * FROM record`
    return query(_sql)
  }
  findData(date){
      var sql = tables.record.select(`*`, `strftime('%s',time)*1000  as time`).where(`strftime('%s',time)*1000 > ${date}`).toQuery();
      return query(sql.text, sql.values);
    
  }
  insertData(data) {
    let _sql = `insert into record set key=?, data=?;`
    return query(_sql, data)
  }   
  insert(type, data) {
    let sql = tables.record.insert(tables.record.type.value(type), tables.record.data.value(data)).toQuery();
    return query(sql.text, sql.values);
  }
  test(){
  
       var sql = tables.record.select("*", "strftime('%s',time)*1000  as time").where("time > '0'").toQuery();
     // let  _sql = `SELECT *,strftime('%s',time)*1000  as time FROM record where time > '0'`
                   
      return query(sql.text, sql.values);
    //let query = config.recode.insert(config.record.type.value("a"), config.record.data.value("b csfe")).toQuery();
   // return sqlite.query(query.text, query.values);
  }
  
  deleteData(id) {
    let _sql = `delete from record where id='${id}';`
    return query(_sql, [])
  }
  updateData(data) {
    let _sql = `update record set key=? where data=?;`
    return query(_sql, data)
  }
}

module.exports = new recordSql